from rest_framework.response import Response
from rest_framework.views import exception_handler

import logging
logger = logging.getLogger('django')

def custom_exception_handler(exc, context):

    response = exception_handler(exc, context)

    if response is None:

        view = context['view']
        error = '服务器内部错误: %s, %s' % (view, exc)
        logger.error(error)
        return Response({'message': error}, status=500)

    return response